package com.api.oa.mapper;

import com.api.oa.model.entity.YQFace;
import com.api.oa.model.vo.OaNoticeVo;
import com.api.oa.model.vo.YQFaceVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface YQFaceMapper {

    @Insert("insert into  yq_user_face  (" +
        "userId," +
        "faceBlob," +
        "featureBlob," +
        "createdAt" +
    ") " +
    "values " +
    "(" +
        "#{entity.userId}," +
        "#{entity.faceBlob}," +
        "#{entity.featureBlob}," +
        "#{entity.createdAt}" +
    ")" )
    @Options(useGeneratedKeys = true, keyProperty = "faceId", keyColumn = "id")
    Integer insert(@Param("entity") YQFace entity);



    @Update("update  yq_user_face  set " +
        "faceBlob = #{entity.faceBlob}," +
        "featureBlob = #{entity.featureBlob}" +
    " where userId = #{entity.userId}")
    Integer update(@Param("entity") YQFace entity);


    @Delete("delete from yq_user_face where faceId=#{id}")
    void delete(@Param("id") Long id);

   //
    @Select("<script> select yq_user_face.*,yq_user.uname as userName,yq_user.userType as role from  yq_user_face left join yq_user on yq_user_face.userId = yq_user.userId " +
            "  where 1 = 1 " +
            "<if test='keyWord!=null and keyWord!=\"\"'> and yq_user.uname like concat('%',#{keyWord},'%') </if>"+
            "<if test='role!=null and role!=\"\"'> and yq_user.userType = #{role} </if>"+
            "<if test='insCode!=null and insCode!=\"\"'> and yq_user.belongInsCode =#{insCode} </if>  </script>")
    List<YQFaceVO> list(@Param("insCode") String  insCode,@Param("keyWord") String keyWord,@Param("role") String role);


    @Select("select * from  yq_user_face  where faceId = #{id} limit 1")
    YQFace findOne(@Param("id") Long id);



    @Select("select * from  yq_user_face  where userId = #{id} limit 1")
    YQFace findOneByUserId(@Param("id") Long id);



    @Select("<script> select v_yq_patient_user.* from  yq_user_face right join v_yq_patient_user on yq_user_face.userId = v_yq_patient_user.userId " +
            "  where 1 = 1  and yq_user_face.faceBlob is null " +
            "  <if test='insCode!=null and insCode!=\"\"'> and v_yq_patient_user.patientIns =#{insCode} </if> " +
            "  <if test='keyWord!=null and keyWord!=\"\"'> and concat(ifnull(v_yq_patient_user.patientName,''),ifnull(v_yq_patient_user.patientIdCard,'')) like concat('%',#{keyWord},'%') </if> " +
            "  <if test='attendType!=null and attendType!=\"\"'> and v_yq_patient_user.attendType =#{attendType} </if> </script>")
    List<YQFaceVO> patientFace(@Param("insCode") String  insCode,@Param("attendType") String attendType,@Param("keyWord") String keyWord);

}

